package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.Invitation;
import com.ruoyi.web.ydz.service.IInvitationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 论坛提问Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/ydz/invitation")
public class InvitationController extends BaseController
{
    @Resource
    private IInvitationService invitationService;

    /**
     * 查询论坛提问列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Invitation invitation)
    {
        List<Invitation> list = invitationService.selectInvitationList(invitation);
        return getDataTable(list);
    }

    /**
     * 导出论坛提问列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:export')")
    @Log(title = "论坛提问", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Invitation invitation)
    {
        List<Invitation> list = invitationService.selectInvitationList(invitation);
        ExcelUtil<Invitation> util = new ExcelUtil<Invitation>(Invitation.class);
        util.exportExcel(response, list, "论坛提问数据");
    }

    /**
     * 获取论坛提问详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invitationService.selectInvitationById(id));
    }

    /**
     * 新增论坛提问
     */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:add')")
    @Log(title = "论坛提问", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody Invitation invitation, HttpServletRequest request)
    {
        return toAjax(invitationService.insertInvitation(invitation,request));
    }

    /**
     * 修改论坛提问
     */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:edit')")
    @Log(title = "论坛提问", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Invitation invitation)
    {
        return toAjax(invitationService.updateInvitation(invitation));
    }

    /**
     * 删除论坛提问
     */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:remove')")
    @Log(title = "论坛提问", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invitationService.deleteInvitationByIds(ids));
    }

    /*
    * 审核帖子
    * */
    @PreAuthorize("@ss.hasPermi('ydz:invitation:edit')")
    @Log(title = "审核帖子", businessType = BusinessType.UPDATE)
    @PostMapping("/examineInvitation")
    public AjaxResult examineInvitation(@RequestBody Invitation invitation){
        return invitationService.examineInvitation(invitation);
    }

    /*
    * h5获取论坛列表
    * */
    @RequestMapping("/getInvitationList")
    public TableDataInfo getInvitationList(@RequestBody Invitation invitation){
        List<Invitation> invitationList = invitationService.getInvitationList(invitation);
        return getDataTable(invitationList);
    }
    /*
    * h5首页获取最热 最新论坛表
    * */

}





















